package com.example.jpademo.Service;

import com.example.jpademo.DAO.AuthorDAO;
import com.example.jpademo.Entity.Author;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.persistence.criteria.CriteriaBuilder;
import java.util.List;

@Service
public class AuthorService {
    @Autowired
    AuthorDAO authorDAO;
    //增（注册）
    public void addAuthor(Author author){
        authorDAO.save(author);
    }
    //登录
    public String login(Author author){
            Integer authorId= authorDAO.login(author.getEmail(),author.getPassword());
            System.out.println(author.getEmail()+author.getPassword()+authorId);
            if(authorId == null){
                return "用户名或密码错误";
            }else{
                author.setId(authorId);
                return "登录成功";
            }
    }
    //查（返回所有作者信息）
    public List<Author> getAllAuthor(){
        return authorDAO.findAll();
    }
    //删（注销）
    public void deleteAuthor(Integer id){
        authorDAO.deleteById(id);
    }
    //改（修改自己信息）
    // ？？
    public void updateAuthor(Author author) {
        authorDAO.save(author);
    }
}
